<template>
	<view>
		<uni-card :is-shadow="false">
			<text class="uni-body f-jc">{{user.username}}&nbsp;欢迎登录</text>
			<uni-list>
				<uni-list-item title="用户名" :rightText="user.username" />
				<uni-list-item title="手机号" :rightText="user.phone" />
				<uni-list-item title="邮箱" :rightText="user.email" />
			</uni-list>
		</uni-card>
		<button @click="toEditPass">修改密码</button>
		<!-- <button @click="bindOpenId">绑定微信</button> -->
		<button @click="toEditInfo">修改信息</button>
		<button @click="logout">退出登录</button>
		
		
		<!-- 提示信息弹窗 -->
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msg.msgType" :message="msg.messageText" :duration="2000"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	import { getUserById } from '../../api/person.js'
	export default {
		data() {
			return {
				msg: {},
				user: {}
			}
		},
		onShow() {
			this.user = this.$utils.getStorage('user')
			this.getUserInfo()
		},
		methods: {
			messageToggle(type, msg) {
				this.message.msgType = type
				this.message.messageText = msg
				this.$refs.message.open()
			},
			getUserInfo(){
				getUserById(this.$utils.getStorage('uid')).then(res => {
					if(res.code === 200){
						this.user = res.data
					}else{
						this.msg = this.$utils.messageError(res.msg)
						this.$refs.message.open()
					}
				})
			},
			logout(){
				this.$utils.clearStorage()
				this.msg = this.$utils.messageSuccess('退出登录成功')
				this.$refs.message.open()
				uni.redirectTo({
					url: '/pages/login/login'
				});
			},
			bindOpenId(){
			},
			toEditPass(){
				uni.navigateTo({
					url: 'editPass'
				})
			},
			toEditInfo(){
				uni.navigateTo({
					url: 'editInfo'
				})
			}
		}
	}
</script>

<style>

</style>
